/*
 * CPoisonDeadlyDOTEvent.java
 * 
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 * 
 * This file is part of JRogueDPS.
 * 
 * JRogueDPS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * JRogueDPS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with JRogueDPS.  If not, see <http://www.gnu.org/licenses/>.
 */

package dpssystem;

import dpssystem.CAttackChance.HitType;
import java.util.ArrayList;

/**
 *
 * @author Giles Millward (Manigra)
 */
public class CPoisonDeadlyDOTEvent extends CEvent {

    CPoisonDeadlyDOT m_deadlyPoisonDOT;

    CPoisonDeadlyDOTEvent(double p_eventTime, CPoisonDeadlyDOT p_deadlyPoisonDOT)
    {
        super(p_eventTime);
        m_deadlyPoisonDOT = p_deadlyPoisonDOT;
    }

    public ArrayList<CEvent>runEvent(CSim p_sim)
    {
        // DOT Tick on deadly poison needed

        // Only run calculation if there is time and we have stacks,
        // envenom can remove the stack when used so it might disappear
        // unexpectedly
        if (m_deadlyPoisonDOT.m_stacks != 0)
        {
            if (p_sim.m_currentRunTime <= (m_deadlyPoisonDOT.m_endOfDOT + 0.02))
            {
                // Okay we can tick on this, work out how much damage we can do
                // and apply it.
                double l_damage = 74 + p_sim.m_baseStats.getAttackPower() * 0.03;
                l_damage *= m_deadlyPoisonDOT.m_stacks;
                l_damage *= m_deadlyPoisonDOT.m_vilePoisonBoost;
                // Resistance
                double l_resisted = (l_damage * 0.06);
                l_damage -= l_resisted;

                m_deadlyPoisonDOT.m_damageStats.addStats(HitType.NORMAL, l_damage);
                m_deadlyPoisonDOT.m_stackStats.addTick(m_deadlyPoisonDOT.m_stacks - 1, l_damage);

                p_sim.m_player.m_energyRegen.tier8_2PieceBonus();
            }

            //p_sim.log("DP Tick for " + l_damage + " at " + m_deadlyPoisonDOT.m_stacks + " stacks");

            // Schedule up another event
            ArrayList<CEvent> l_newEventList = new ArrayList<CEvent>();
            l_newEventList.add(new CPoisonDeadlyDOTEvent(p_sim.m_currentRunTime + 3.0, m_deadlyPoisonDOT));
            return l_newEventList;
        }
        else
        {
            // Way over time so don't apply tick and reset
            // DOT stack
            //p_sim.log("DP stack fell off");
            m_deadlyPoisonDOT.resetDOT();
        }

        return null;
    }
}
